package com.qidian.controller;


import com.qidian.pojo.StudentInfo;
import com.qidian.service.StudentInfoService;
import com.qidian.util.LayuiDataList;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import javax.annotation.Resource;

/**
 * (StudentInfo)控制层
 *
 * @author 戴着假发的程序员
 * @since 2022-03-01 08:47:07
 */
@RestController
@RequestMapping("/studentInfo")
public class StudentInfoController {
    /**
     * 服务对象
     */
    @Resource
    private StudentInfoService studentInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param studentInfo 参数对象
     * @return 单条数据
     */
    @RequestMapping(value = "get", method = RequestMethod.GET)
    public StudentInfo selectOne(StudentInfo studentInfo) {
        StudentInfo result = studentInfoService.selectById(studentInfo.getStudentId());
        if(result != null){
          return  result;
        }
        return null;
    }
    
    /**
     * 新增一条数据
     *
     * @param studentInfo 实体类
     * @return Map
     */
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public Map insert(StudentInfo studentInfo) {
        Map map = new HashMap();
        map.put("code",200);
        int result = studentInfoService.insert(studentInfo);
        if (result <= 0) {
          map.put("code",500);
        }
        return map;
    }

    /**
     * 修改一条数据
     *
     * @param studentInfo 实体类
     * @return Response对象
     */
    @RequestMapping(value = "update")
    public Map update(StudentInfo studentInfo) {
        Map map = new HashMap();
        map.put("code",200);
        StudentInfo result = studentInfoService.update(studentInfo);
        if (result != null) {
            map.put("data",result);
        }else{
            map.put("code",500);
        }
        return map;
    }

    /**
     * 删除一条数据
     *
     * @param studentInfo 参数对象
     * @return Response对象
     */
    @RequestMapping(value = "delete")
    public Map delete(StudentInfo studentInfo) {
        Map map = new HashMap();
        map.put("code",200);
        int result = studentInfoService.deleteById(studentInfo.getStudentId());
        if (result <= 0) {
           map.put("code",500);
        }
        return map;
    }

     /**
     * 批量删除
     *
     * @param ids
     * @return Response对象
     */
    @RequestMapping(value = "deletes")
    public Map deletes(Long [] ids) {
        Map map = new HashMap();
        map.put("code",200);
        int result = studentInfoService.deleteByIds(ids);
        if (result <= 0) {
           map.put("code",500);
        }
        return map;
    }

    /**
     * 查询全部
     *
     * @return Response对象
     */
    @RequestMapping(value = "selectAll")
    public List<StudentInfo> selectAll() {
        return studentInfoService.selectAll();
    }

    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return List<StudentInfo>
     */
    @RequestMapping(value = "selectPage", method = RequestMethod.GET)
    public List<StudentInfo> selectPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit) {
        return studentInfoService.selectPage(page, limit);
    }
    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return List<StudentInfo>
     */
    @RequestMapping(value = "selectPageByPojo", method = RequestMethod.GET)
    public List<StudentInfo> selectPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit,StudentInfo studentInfo) {
        return studentInfoService.selectPage(page, limit,studentInfo);
    }

    /**
     * 分页查询
     *
     * @param page 偏移
     * @param limit 条数
     * @return Response对象
     */
    @RequestMapping(value = "selectPageForLayui")
    public LayuiDataList<StudentInfo> selectPageForLayui(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit, StudentInfo studentInfo) {
        return studentInfoService.selectPageForLayui(page, limit,studentInfo);
    }

    
}